﻿/**
作者：魏铁雷
时间：209-11-21
功能：实现栏目增加
**/
var ModelId = "";
var rd_flg = "1"; //单选按钮默认是1启用状态

var UploadActionPath = SBasePath + "/action/upload/";
var ContactUsImageArray = new Array();
var ImageArr = new Array('.jpg', '.gif', '.png', '.bmp', '.swf', '.rar'); //形象图片类型
var UploadType = 1; //1:缩略图2:原图
var _mDebug = false; //用于调试显示上传显示部分

function ShowMain() {
    ModelId = request("modelid");
    ShowContent();
}
//提交
var Add_Model = function() {
    if (CheckAddForm()) {
        var url = encodeURI(SBasePath + '/action/ModelManage/AddModel.aspx');
        var myAjax = new Ajax.Request(url, { method: 'post', parameters: Form.serialize("formModel"), onComplete: sAddModels, onFailure: fAddModels });
    }
};

var sAddModels = function(o) {
    var root = o.responseXML.documentElement;
    var flag = GetXmlData(root, "Value");
    if (flag == "true") {
        MsgDlgLocal("添加成功！")

    } else {
        MsgDlg("添加失败！")

    }
};

var fAddModels = function(o) {

};

var CheckAddForm = function() {

    var fobj = $("formModel");

    if (fobj.lmmc.value == "") {
        alert("栏目名称不能为空");
        fobj.lmmc.focus();
        return false;
    }

    if (fobj.ywmc.value == "") {

        alert("英文名称不能为空");
        fobj.ywmc.focus();
        return false;
    }
    if (fobj.ModelUrl.value == "") {

        alert("模块路径不能为空");
        fobj.ModelUrl.focus();
        return false;
    }
    if (fobj.order.value == "") {

        alert("编号不能为空");
        fobj.order.focus();
        return false;
    }
    if (fobj.jy.checked == true) {
        rd_flg = "0";
        fobj.rd.value = rd_flg;

    }
    return true;
};

function ShowContent() {
    var str = "";
    str += '<form id="formModel">';
    str += '<input type="hidden" name="ShrinUrl" id="ShrinUrl" value="">';
    str+= '<input type="hidden" id="mid" name="mid" value="' + ModelId + '"/>';
    str+= '<input type="hidden" id="rd" name="rd" value="'+rd_flg+'"/>';
    str+=' <table width="100%" height="100%" border="0" align="center" cellpadding="0" cellspacing="0">';
    str+='<tr>';
    str+='    <td height="30">';
    str+='        <table width="100%" border="0" cellspacing="0" cellpadding="0">';
    str+='            <tr>';
    str+='                <td width="15" height="30" class="tab03">';
    str+='                </td>';
    str+='                <td class="tab05">';
    str+='                    <div class="title1" style="padding-top: 2px">';
    str+='                        <img src="../../img/1.gif" height="20" width="19" />添加栏目</div>';
    str+='                </td>';
    str+='                <td width="14" class="tab07"></td>';
    str+='            </tr>';
    str+='        </table>';
    str+='    </td>';
    str+='</tr>';
    str+='<tr>';
    str+='    <td>';
    str+='        <table width="100%" border="0" cellspacing="0" cellpadding="0">';
    str+='            <tr>';
    str+='                <td width="9" class="tab12"></td>';
        str+='                <td bgcolor="#f3ffe3">';
        str+='                    <table width="100%" border="0" cellspacing="0" cellpadding="0">';
        str+='                        <tr>';
        str+='                            <td class="k_hui">';
        str+='                                <table width="97%" border="0" cellspacing="0" cellpadding="0" align="center">';
        str+= '                                    <tr height="38">';
        str+='                                        <td height="30" width="15%" style="padding-left: 5px">';
        str+= '                                            栏目名称：';
        str+='                                        </td>';
        str+='                                        <td width="80%">';
        str+= '                                            <input type="text" name="lmmc" id="lmmc" value="" class="wbk" />';
        str+='                                        </td>';
        str+='                                    </tr>';
        str+= '                                    <tr height="38">';
        str+='                                        <td height="30" width="12%" style="padding-left: 5px">';
        str+= '                                            英文名称：';
        str+='                                        </td>';
        str+='                                        <td widht="35%">';
        str+= '                                            <input type="text" name="ywmc" id="ywmc" value="" class="wbk"/>';
        str+='                                        </td>';
        str+='                                    </tr>';
        str+= '                                    <tr height="38">';
        str+='                                        <td height="30" width="12%" style="padding-left: 5px">';
        str+= '                                            排序编号：';
        str+='                                        </td>';
        str+='                                        <td widht="25%">';
        str+= '                                            <input type="text" name="order" id="order" value="" class="wbk"/>';
        str+='                                        </td>';
        str+= '                                   </tr>';
        str+= '                                    <tr height="38">';
        str+= '                                        <td height="30" width="12%" style="padding-left: 5px">';
        str+= '                                            模块路径：';
        str+= '                                        </td>';
        str+= '                                        <td widht="25%">';
        str+= '                                            <input type="text" name="ModelUrl" id="ModelUrl" value="" class="wbk"/>';
        str+= '                                        </td>';
        str += '                                   </tr>';
        str += '                                    <tr height="38">';
        str += '                                        <td height="30" width="12%" style="padding-left: 5px">';
        str += '                                            链接：';
        str += '                                        </td>';
        str += '                                        <td widht="25%">';
        str += '                                            <input type="text" name="HttpUrl" id="HttpUrl" value="" class="wbk"/>';
        str += '                                        </td>';
        str += '                                   </tr>';
        str += '                                    <tr height="38">';
        str += '                                        <td height="30" width="12%" style="padding-left: 5px">';
        str += '                                            启用状态：';
        str += '                                        </td>';
        str += '                                        <td widht="25%">';
        str += '                                            <input type="radio" name="zt"  checked=true id="qy" value=""/>启用<input type="radio" name="zt" id="jy" value=""/>禁用';
        str += '                                        </td>';
        str += '                                   </tr>';

        str += '                                    <tr height="38">';
        str += '                                        <td height="30" width="12%" style="padding-left: 5px">';
        str += '                                            图片格式：';
        str += '                                        </td>';
        str += '                                        <td widht="80%">';
        str += '               <input type="radio" name="imgwh"   id="small" value="0"/>小图:240*60(宽*高)<input type="radio" name="imgwh" id="big" value="1"/>大图:740*110(宽*高)<font color="red">【请上传正确大小图片】</font>';
        str += '                                        </td>';
        str += '                                   </tr>';
        
        str += '</form>';
        
        str += '                                    <tr height="38">';
        str += '                                        <td height="30" width="12%" style="padding-left: 5px">';
        str += '                                            专题图片：';
        str += '                                        </td>';
        
        str += '              <td widht="80%">';
        str += '                <form name="myform" id="myform" action="' + UploadActionPath + 'UploadCommResult.aspx"; method="post" enctype="multipart/form-data" target="targethidenfram">';
        str += '                <input type="file" value="" name="file1" id="file1" class="input2">';
        str += '                <input onclick="StartUpload(\'myform\',\'1\');" type="button" name="SubmitButton" id="SubmitButton"   style="height:23"  value="上传">';
        str += '                <div id="progressout"></div>';
        str += '                <div id="ShrinImageDiv"></div>';
        str += '                 </form>'; 
        str += '              </td>';
        str += '                                   </tr>';
        
        str+='                                    <tr height="38">';
        str+='                                        <td colspan="2" style="padding-left: 25px" height="30">';
        str+= '                                             <input name="提交" type="button" class="bg_g" style="height: 22px; width: 60px; border: solid 1px #cadcb2;"value="提交" onclick="Add_Model();" />';
        str+='                                            &nbsp;&nbsp;<input name="重置" type="reset" class="bg_g" style="height: 22px; width: 60px;border: solid 1px #cadcb2;" value="重置" />';
        str+='                                        </td>';
        str+='                                        <td width="52%" class="zw">';
        str+='                                        </td>';
        str+='                                    </tr>';
        str+='                                </table>';
        str+='                             </td>';
        str+='                        </tr>';
        str+='                    </table>';
        str+='                </td>';
        str+='                <td width="9" class="tab16">';
        str+='                </td>';
        str+='            </tr>';
        str+='        </table>';
        str+='    </td>';
        str+='</tr>';
        str+='<tr>';
        str+='    <td height="29">';
        str+='        <table width="100%" border="0" cellspacing="0" cellpadding="0">';
        str+='            <tr>';
        str+='                <td width="15" height="29" class="tab20">';
        str+='                </td>';
        str+='                <td class="tab21">';
        str+='                    &nbsp;';
        str+='                </td>';
        str+='                <td width="14" class="tab22">';
        str+='                </td>';
        str+='            </tr>';
        str+='        </table>';
        str+='    </td>';
        str+='</tr>';
        str+= '</table>';
   
        if (_mDebug) {
            str += '  <iframe id="targethidenfram" name="targethidenfram" frameborder="0" height="200" width="400" visible="false"></iframe>';
        }
        else {
            str += '  <iframe id="targethidenfram" name="targethidenfram" frameborder="0" height="0" width="0" visible="false"></iframe>';
        }

        $("ModelAdd").innerHTML=str;
    }

    /*-------------------------------------------以下关于上传-------------------------------------------------*/
    var progressWindow;
    function StartUpload(formObj, Type)//开始上传
    {
       
        UploadType = Type;
        if (chkGroupImageFileValid()) {
            if (typeof (formObj) == "string")
                formObj = document.getElementById(formObj);
            //Show Cancel button
            var CancelButton = document.getElementById("CancelButton");
            if (CancelButton && PowUploadCanCancel())
                CancelButton.style.visibility = "visible";

            var uniqueID = Math.floor(Math.random() * 10000000) + (new Date()).getTime() % 1000000000;
            progressWindow = ShowProgressInFrame(uniqueID, UploadActionPath + 'Progress.aspx', 400, 200); //显示进度条	

            thePos = formObj.action.indexOf("UploadID");
            //Cut earlier added UploadID.
            if (thePos >= 1)
                formObj.action = formObj.action.substring(0, thePos - 1);
            if (formObj.action.indexOf("?") == -1)
                formObj.action += '?UploadID=' + uniqueID
            else
                formObj.action += '&UploadID=' + uniqueID;
            formObj.submit();
            return true;
        }
    }

    //Function ShowProgressInNewWindow() to show progress bar in new window.
    function ShowProgressInFrame(uniqueID, URL, width, height) {
        var l = (screen.width - width) / 2;
        var t = (screen.height - height) / 2;
        //	var winParams = 'toolbar=no,scrollbars=no,location=no,status=no,menubar=no,resizable=yes';
        //	winParams += ',width=' + width + ',height=' + height + ',left=' + l + ',top=' + t;
        var fullURL = URL;
        thePos = fullURL.indexOf("UploadID");
        //Cut earlier added UploadID.
        if (thePos >= 1)
            fullURL = fullURL.substring(0, thePos - 1);
        if (URL.indexOf("?") == -1)
            fullURL += '?UploadID=' + uniqueID;
        else
            fullURL += '&UploadID=' + uniqueID;
        $("progressout").innerHTML = '<iframe id="progressframe" name="' + uniqueID + '" frameborder="0" height="' + height + '" width="' + width + '" visible="true" src="' + fullURL + '" SCROLLING="no"></iframe>';
        //var newProgressWindow = window.open(fullURL, uniqueID, winParams);
        var newProgressWindow = $("progressframe");
        return newProgressWindow;
    }

    //上传成功后的回调函数
    function UploadCommplete(fobjs) {

        var str = "";
        var filename = "";
        if (fobjs != null) {
            for (var i = 0; i < fobjs.length; i++) {
                str += fobjs[i].FileName + "<br>";
                if (fobjs[i].FileName != "") {
                    filename = fobjs[i].FileName;
                }
            }
        }

        $("progressout").style.display = "none";
        if (UploadType == 1) {
            //  $("ShrinImageDiv").innerHTML = '<img src="/web' + filename + '" width="300" height="300" />';
            $("ShrinImageDiv").innerHTML = '<a href="/web' + filename + '" target="_blank" >上传成功</a>';
            $("ShrinUrl").value = filename;
        }
        else {
            ContactUsImageArray[ContactUsImageArray.length++] = filename;
            ShowContactUsImage(ContactUsImageArray);
        }


    }

    //检查形象图片的合法性
    function chkGroupImageFileValid() {
        var objs = null;
        if (UploadType == 1) {

            objs = $("file1");
        }
        else {
            objs = $("file2");
        }

        if (objs.value == "") {
            MsgDlg("您还没有选择任何文件!");
            return false;
        }
        else {
            var name = objs.value;
            name = name.substring(name.lastIndexOf('.'));
            for (var i = 0; i < ImageArr.length; i++) {
                if (name.toLowerCase() == ImageArr[i]) {
                    return true;
                }
            }
            MsgDlg("您所选择的文件类型不对!");
            return false;
        }
    }
    
    